<template>
  <div class="rechange">
    <header>
      <span @click.stop="$back()"><el-icon size="18">
          <Back />
        </el-icon></span>
      <dl>
        <dd v-for="(item, index) in tab" :class="activeindex == index ? 'active' : ''" @click="activeindex = index">
          {{ $t(item) }}
        </dd>
      </dl>
      <strong></strong>
    </header>
    <main class="main">
      <template v-if="activeindex == 0">
        <AppSkeleton :loading="loading">
          <template #ske>
            <div style="
            width: 100%;
            display: flex;
            justify-content: start;
            align-items: center;
            padding: 0 16px;
          ">
              <el-skeleton-item variant="text" style="width: 60px; height: 36px; margin: 10px 10px 0px 0" />
              <el-skeleton-item variant="text" style="width: 60px; height: 36px; margin: 10px 0 0px 0" />
            </div>
          </template>
          <template #main>
            <ul>
              <li v-for="(item, index) in bar" :class="activeBindex == index ? 'activeB' : ''"
                @click="activeBindex = index">
                <NuxtImg :src="item.img" alt="" />
                <strong>{{ item.name }}</strong>
              </li>
            </ul>
          </template>
        </AppSkeleton>

        <component :loading="loading" :is="activeBindex == 0 ? BRL : USDT" />
      </template>
      <template v-else>
        <dl class="record" v-if="recordinfo.list.length != 0">
          <dd v-for="(item, index) in recordinfo.list" :key="index">
            <p class="time">{{ item.date }}</p>
            <div class="record-item" v-for="child in item.data " :key="child.orderID">
              <div>
                <p>{{ $t('language.rechange.orderID') }}: {{ child.orderID }}</p>
                <i>{{ $t('language.rechange.copy') }}</i>
              </div>
              <span>{{ $t('language.rechange.RechargeAmount') }}: <strong>{{ child.amount / 100 }}R$</strong></span>
              <div class="status">
                <strong>{{ child.orderDate }}</strong>
                <span v-if="child.orderStatus == 0">{{ $t('language.rechange.waitpay') }}</span>
                <span v-else style="color: #0c730c;">{{ $t('language.rechange.paysuccess') }}</span>

              </div>
            </div>
          </dd>
        </dl>
        <div class="nodata" v-if="recordinfo.list.length == 0 && !loadingrecord">
          <NuxtImg src="/img/bg4.png" alt="" />
          <p>{{ $t("language.rechange.tips") }}</p>
        </div>
      </template>
    </main>
  </div>

</template>
<script setup lang="ts">
definePageMeta({
  layout: false,
})
import { Back } from '@element-plus/icons-vue'
import { reactive, ref,shallowReactive,shallowRef, nextTick, watch } from "vue";
import BRL from "./rechange/components/rechangeBRL.vue";
import USDT from "./rechange/components/rechangeUSDT.vue";
const router: any = useRoute()
let loading = shallowRef<boolean>(false);
// 判断是否跳转订单记录
let activeindex = shallowRef<number>(0);
Object.keys(router.query).length != 0 ? activeindex.value = router.query.index : activeindex.value = 0
//标题索引值
let activeBindex = ref<number>(0);
let tab = shallowReactive<string[]>(["language.rechange.title1", "language.rechange.title2"]);
let bar = reactive<{img:string,name:string}[]>([
  {
    img: "/img/mylrft.png",
    name: "BRL",
  },
  {
    img: "/img/t1.png",
    name: "USDT",
  },
]);
//获取充值数据
let store = useStore()
let info = computed(() => store.userinfo)
//获取充值记录
let record = reactive({
  id: info.value.gameID,
  pageIndex: 1,
  pageSize: 30
})
//订单记录信息
let recordinfo: any = reactive({
  list: [],
  pageIndex: 1,
  pageSize: 11,
  totalCount: 23
})
let loadingrecord = shallowRef<boolean>(false)
//监听页面索引值是否变化并获取充值记录
watch(() => activeindex.value, (newValue) => {
  if (newValue == 1) {
    loadingrecord.value = true
    ElLoading.service({
      lock: true,
      background: 'rgba(0, 0, 0, 0.7)',
      customClass: 'el-loading'
    })
    useHttpPOST(`/Payment/v1.0/Web/User/Recharge/List`, record)
      .then(({ data }: { data: any }) => {
        for (let key in data.value.data) {
          recordinfo[key] = data.value.data[key];
        }
      }).finally(() => {
        let time = setInterval(() => {
          ElLoading.service({
            lock: true,
            background: 'rgba(0, 0, 0, 0.7)',
            customClass: 'el-loading'
          }).close()
          loadingrecord.value = false
          clearInterval(time)
        }, 500)

      });
  }
}, {
  immediate: true
})


//dom更新后执行
nextTick(() => {
  let time = setInterval(() => {
    loading.value = false;
    clearInterval(time);
  }, 500);
});


</script>
<style lang="scss">
.redialog {
  #bigcloser {
    width: 100%;
    @include flex(row, flex-end, center);

    strong {
      display: block;
      width: 28px;
      height: 28px;
    }

    h4 {
      flex: 1;
      font-size: 18px;
      color: #fff;
      text-align: center;
    }

    span {
      display: block;
      width: 28px;
      height: 28px;
      @include flex(row, center, center);
      border: 2px solid #b5b6c8;
      border-radius: 16px;
      margin-right: -7px;
    }
  }

  .el-dialog {
    padding: 15px !important;
    background-color: rgb(50, 53, 62) !important;
    border-radius: 10px !important;
  }

  .dialogmain {
    .confirm {
      background: #0a906c;
      border: none;
      color: #fff;
      display: block;
      width: 40%;
      height: 40px;
      line-height: 40px;
      font-size: 14px;
      color: #fff;
      text-align: center;
      border-radius: 5px;
      margin: 10px auto 20px;
    }

    .note {
      font-size: 14px;
      color: red;
      line-height: 23px;
      margin-top: 10px;
      text-align: left;
    }
  }

  .el-dialog__header {
    padding: 0 !important;
  }
}
</style>
<style scoped lang="scss">
.rechange {
  width: 100%;

  header {
    width: 100%;
    position: fixed;
    left: 0;
    top: 0;
    @include flex(row, space-between, center);
    background-color: rgb(36, 39, 43);
    padding: 20px 20px 6px;
    color: #fff;

    span {
      display: block;
      height: 30px;
      width: 30px;
      @include flex(row, center, center);
      border: 2px solid #fff;
      border-radius: 16px;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }

    strong {
      width: 34px;
      height: 34px;
      display: block;
    }

    dl {
      flex: 1;
      @include flex(row, center, center);

      dd {
        color: #8e8e8c;
        font-size: 18px;
        position: relative;
        cursor: pointer;
      }

      .active {
        color: #fff;

        &::after {
          content: "";
          position: absolute;
          width: 60%;
          bottom: -4px;
          height: 2px;
          background-color: #fff;
          margin-left: -30%;
          left: 50%;
        }
      }

      dd+dd {
        margin-left: 20px;
      }
    }
  }

  .main {
    background-color: #1a1a1a;
    padding: 73px 0px 0px;
    width: 100%;
    height: 100vh;
    background-color: rgb(26, 26, 26);
    box-sizing: border-box;

    >ul {
      height: 44px;
      width: 100%;
      padding: 0 16px;
      @include flex(row, flex-start, center);

      li {
        height: 44px;
        cursor: pointer;
        @include flex(row, flex-start, center);
        border-bottom: 2px solid transparent;

        img {
          width: 24px;
          margin-right: 5px;
        }

        strong {
          color: #b5bac8;
          font-size: 17px;
        }
      }

      .activeB {
        strong {
          color: #0a906c;
        }

        border-bottom: 2px solid #0a906c;
      }

      li+li {
        margin-left: 20px;
      }
    }

    .record {
      width: 100%;

      dd {
        width: 100%;

        >p {
          height: 40px;
          width: 100%;
          padding: 0 16px;
          line-height: 40px;
          font-size: 14px;
          background-color: #40434c;
          color: #b5bac8;
        }

        .record-item {
          padding: 16px;

          >div {
            @include flex(row, space-between, center);

            p {
              color: #fff;
              font-size: 14px;
            }

            i {
              font-style: normal;
              color: #0a906c;
              font-size: 15px;
            }
          }

          >span {
            font-size: 14px;
            color: #fff;
            display: block;
            margin: 6px 0;
          }

          .status {
            @include flex(row, space-between, center);

            strong {
              color: #666;
              font-weight: normal;
            }

            span {
              font-size: 14px;
              color: #f9e009;
            }
          }
        }

        .record-item+.record-item {
          border-top: 1px solid #40434c;
        }
      }

    }

    .nodata {
      width: 100%;
      height: 400px;

      img {
        width: 200px;
      }

      @include flex(column, center, center);

      p {
        font-size: 17px;
        color: #b5bac8;
        margin-top: 50px;
      }
    }
  }
}
</style>
